package com.zlkj.pro.modular.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zlkj.pro.core.util.ConvertUtil;
import com.zlkj.pro.modular.admin.service.UsersService;
import com.zlkj.pro.modular.app.service.AppBannerService;
import com.zlkj.pro.modular.business.entity.BannerEntity;
import com.zlkj.pro.modular.business.mapper.BannerMapper;
import com.zlkj.pro.modular.business.model.vo.BannerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class AppBannerServiceImpl extends ServiceImpl<BannerMapper, BannerEntity> implements AppBannerService {


    @Autowired
    UsersService usersService;

    @Autowired
    private Environment env;


    @Override
    public List<BannerVO> findList() {
        LambdaQueryWrapper<BannerEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(BannerEntity::getStatusFlag, 1);
        queryWrapper.orderByAsc(BannerEntity::getDataSort);
        List<BannerEntity> bannerEntityList = super.list(queryWrapper);
        List<BannerVO> list = ConvertUtil.turn(bannerEntityList, BannerVO.class);
        list.forEach(b -> {
            b.setImageFileUrl(env.getProperty("file-path") + b.getImageFileId());
        });
        return list;
    }

}
